﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace TB_WS.ASMX
{
    /// <summary>
    /// Rate_Manage 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class Rate_Manage : System.Web.Services.WebService
    {

       [WebMethod(Description ="获取历史评价并处理")]
       public string GET_HISTORY_RATE(string S_Rate_Type,int Low,int Top)
        {
            try
            {
                int p = 0;
                string RT = "";
                string sql = "select * from HB_Log where Log_Str like '评价提前查询%" + S_Rate_Type + "%' and id > "+Low+" and id < "+Top+" order by id desc";
                DataSet RT_DST = Class.Unit.db_Conn.select(sql);
                for (int j = 0; j < RT_DST.Tables[0].Rows.Count; j++)
                {
                    string RT_string = RT_DST.Tables[0].Rows[j][1].ToString();

                    string Seller_Nick = RT_string.Split('\n')[0].Split(' ')[1].Split('：')[1].Split('\t')[0].ToString();
                    int Seller_ID = Convert.ToInt32(Class.Seller_Manage.select_Seller_Info(Seller_Nick).Tables[0].Rows[0][0].ToString());

                    string Tids = RT_string.Split('\n')[0].Split('#')[1].Split('：')[1].ToString();
                    string Rate_Type = RT_string.Split('\n')[1].Split('：')[1].ToString();
                    string Buyer_Nick = RT_string.Split('\n')[2].Split('：')[1].ToString();
                    string Rate_Detail = "";
                    for (int i = 3; i < RT_string.Split('\n').Length; i++)
                    {
                        Rate_Detail += RT_string.Split('\n')[i].ToString();
                    }


                    for (int i = 0; i < RT_DST.Tables[0].Rows.Count; i++)
                    {
                        if (Class.Rate_Control.Get_Rate_Count(Buyer_Nick, Rate_Detail) == 0)
                        {
                            //没有这个差评，添加
                            Class.Rate_Control.INSERT_Rate(Seller_ID, Buyer_Nick, Tids, Rate_Type, Rate_Detail);
                            p++;
                        }
                        else
                        { }
                    }
                }
                return p.ToString();
            }
            catch(Exception EX)
            {
                return EX.ToString();
            }
        }

        [WebMethod(Description ="根据用户昵称获取是否给过别人差评")]
        public DataSet GET_BUYER_NICK_RATE(string BUYER_NICK)
        {
            return Class.Rate_Control.Get_Rate_Use_Buyer_Nick(BUYER_NICK);
        }

        [WebMethod(Description ="获取前几百条中差评列表")]
        public DataSet GET_RATE_LIST_TOP(string Rate_Type,int Top)
        {
            return Class.Rate_Control.Get_Top_Rate(Rate_Type, Top);
        }

        [WebMethod(Description ="新增一条记录评价类型")]
        public void INSERT_RATE(int Seller_ID, string Buyer_Nick, string Tids, string Rate_Type, string Rate_Detail)
        {
            Class.Rate_Control.INSERT_Rate(Seller_ID, Buyer_Nick, Tids, Rate_Type, Rate_Detail);
        }

        [WebMethod(Description ="更新一条评价记录")]
        public void UPDATE_RATE_LOG(int Rate_id,string Rate_Detail)
        {
            Class.Rate_Control.Update_Rate(Rate_id, Rate_Detail);
        }

        [WebMethod(Description ="防火墙订单")]
        public int GET_FW_PUSHED(string Tid)
        {
            int PD_count = Class.Rate_Control.Get_FW_Tid_Pushed(Tid);
            if(PD_count>0)
            {
                //已经存在
                return 1;
            }
            else
            {
                Class.Rate_Control.Insert_FW_Tid(Tid);
                return 0;
            }
        }

        [WebMethod(Description ="同行业订单预警")]
        public int MATCH_CREATE_TRADE()
        {
            return Class.FireWall_Trade.Start_FireWall_Created_Trade();
        }

        [WebMethod(Description ="中差评预警")]
        public int Match_Modified_Trade()
        {
            return Class.FireWall_Trade.Start_FireWall_Rate_Trade();
        }
    }
}
